﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Text.RegularExpressions;
using Subgurim.Controles;

namespace CityGames
{
    public partial class SocioNuevo : System.Web.UI.Page
    {
        Socio socio = new Socio();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (fuaAvatar.IsPosting)
                this.managePost();
        }

        private void managePost()
        {
            HttpPostedFileAJAX pf = fuaAvatar.PostedFile;
            //pf.FileName=socio.Dni;

            if (pf.Type == HttpPostedFileAJAX.fileType.image && pf.ContentLength <= 100 * 1024)
            {
                //fuaAvatar.Save();
                //pf.FileName_SavedAs = tbDni.Text;
                fuaAvatar.SaveAs("/Avatares/", pf.FileName);
                imFoto.ImageUrl = pf.FileName;
            }
        } 

        protected void btRegistro_Click(object sender, EventArgs e)
        {
            try
            {
                socio.Avatar = imFoto.ImageUrl;
                socio.Nombre = tbNombre.Text;
                socio.Apellidos = tbApellidos.Text;
                socio.Dni = tbDni.Text;
                socio.Nick = tbNick.Text;
                socio.Password = tbPassword.Text;
                socio.Email = tbEmail.Text;
                socio.Sexo = rbSexo.SelectedValue;
                socio.Direccion = tbDireccion.Text;
                socio.CP = tbCp.Text;
                socio.Localidad = tbLocalidad.Text;
                socio.Provincia = tbProvincia.Text;
                socio.Telefono = tbTelefono.Text;

                socio.InsertarSocioWeb();

                Session["usuario"] = tbDni.Text;
                Session["password"] = tbPassword.Text;
                Session["tipoUsuario"] = "Socio";

                if (Request.QueryString["origen"] == "carro")
                    Response.Redirect("Carro3.aspx");
                else
                    Response.Redirect("Home.aspx");
            }
            catch (Exception ex)
            {
                MyMessageBoxInfo.Show(MyMessageBox.MessageType.Error, "DNI ya registrado en el sistema", "ERROR", 100, 400);
            }
        }
    }
}